package org.ddr.board.util;

import java.sql.ResultSetMetaData;

import org.ddr.board.dao.BbsAbstractExecutor;
public class VOMetaGenerator {
	public static String getJavaType(String dbType){
		if(dbType.equals("VARCHAR2")){
			return "String";
		}else if(dbType.equals("DATE")){
			return "Date";
		}else if(dbType.equals("NUMBER")){
			return "Integer";
		}
		return null;
	}
	public static void main(String[] args) throws Exception{
		new BbsAbstractExecutor(){
			@Override
			protected void execute() throws Exception {
				
				StringBuffer sql = new StringBuffer();
				sql.append(" select bbs_no, title, contents, read_count, write_date, modify_date, userid ");
				sql.append(" FROM TBL_BBS ");
				sql.append(" WHERE ROWNUM = 1 ");
				
				pstmt = con.prepareStatement(sql.toString());
				rs = pstmt.executeQuery();
				ResultSetMetaData meta = rs.getMetaData();
				
				int count = meta.getColumnCount();
				String ObjectName = "BoardVO";
				System.out.println("public class " + ObjectName + " { ");
				for(int i = 1; i <= count ; i++ ){
					String name = meta.getColumnLabel(i).toLowerCase();
					String type = meta.getColumnTypeName(i);
					String javaType = VOMetaGenerator.getJavaType(type);
					System.out.println("\tprivate " + javaType + " " + name+";" );
				}
				System.out.println(" } ");
			}
		}.doJob();
	}
}



